package com.common.utils;/*
  @author author
  @create 2020-11-21:18:35
*/

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

public class SMSUitl {

    public String SendServer(String phoneNumber){
        RandomUtil randomUtil = new RandomUtil();
        String params = randomUtil.Random();
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4Fz6Az9tBMGHLAD9DBHY", "ozHOkgYZDz00qKhR3eqh1y3P7a0jqG");
        IAcsClient client = new DefaultAcsClient(profile);
        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("PhoneNumbers", phoneNumber);
        /*应用名称*/
        request.putQueryParameter("SignName", "充电桩");
        request.putQueryParameter("TemplateCode", "SMS_205621739");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        /*参数必须是json格式的*/
        request.putQueryParameter("TemplateParam","{\"code\":\""+params+"\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
            return params;
        }  catch (ServerException e) {
            e.printStackTrace();
            return "发生异常";
        } catch (ClientException e) {
            e.printStackTrace();
            return "发生异常";
        }
    }
}
